package com.jlnx.controller.chain;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jlnx.dao.ChainEnterpriseDaoImpl;
import com.jlnx.dao.CoreEnterpriseDaoImpl;
import com.jlnx.dao.EnterpriseDaoImpl;
import com.jlnx.dao.FinanceReqDaoImpl;
import com.jlnx.pojo.ChainEnterprise;
import com.jlnx.pojo.CoreEnterprise;
import com.jlnx.pojo.Enterprise;
import com.jlnx.pojo.FinanceReq;


@WebServlet("/ChangeFinanceReqController")
public class ChangeFinanceReqController extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		//获取请求信息
		response.setContentType("charset=UTF-8");
		//设置请求编码模式
    	request.setCharacterEncoding("utf-8");
    	
    	int reqId = Integer.parseInt(request.getParameter("reqId"));
		String reqName = request.getParameter("reqName");
		String purpose = request.getParameter("purpose");
		String entNo = request.getParameter("entNo");
		BigDecimal reqAmount = new BigDecimal(request.getParameter("reqAmount"));
		String reqTool = request.getParameter("reqTool");
		String product = request.getParameter("product");    
		Date reqDate= new Date();
		String voucherPath = "";
		int reqStatus = 2;
		String reqMassage = request.getParameter("reqMassage");

		FinanceReqDaoImpl dao = new FinanceReqDaoImpl();
		
		//修改相关信息
		FinanceReq financeReq = dao.selectByReqId(reqId);
		System.out.println(financeReq.toString());
		financeReq.setProduct(product);
		financeReq.setPurpose(purpose);
		financeReq.setReqAmount(reqAmount);
		financeReq.setReqMassage(reqMassage);
		financeReq.setVoucherPath(voucherPath);
		financeReq.setReqTool(reqTool);
		financeReq.setReqStatus(reqStatus);
		financeReq.setReqDate(reqDate);
		
		
		 //更新融资请求
		if(dao.changeReqMessageById(reqId, financeReq) < 0) {
			request.setAttribute("isRequestSuccess", false);
			request.setAttribute("message", "提交失败!");
			request.getRequestDispatcher("/FinanceSearchController").forward(request, response);
			
		}else {
			request.setAttribute("isRequestSuccess", true);
			request.setAttribute("message", "提交成功!");
			request.getRequestDispatcher("/FinanceSearchController").forward(request, response);
		}
				
	}

}
